package com.link2room.aeriabots.service.impl;

import com.link2room.aeriabots.constant.WxQrcodeScanConstant;
import com.link2room.aeriabots.entity.WxQrcodeScanDetailEntity;
import com.link2room.aeriabots.service.IScanDetailService;
import com.link2room.common.dao.ICommonDao;
import com.link2room.common.entity.BaseEntity;
import com.link2room.common.jpa.criteria.CriteriaUtil;
import com.link2room.common.jpa.result.QueryResult;
import com.link2room.common.service.ICommonService;
import com.link2room.rodimus.entity.MemberBase;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.HashMap;

/**
 * Created by LN on 2018/4/22
 */
@Component
public class ScanDetailServiceImpl implements IScanDetailService {
    @Resource
    private ICommonDao commonDao;
    @Resource
    private ICommonService commonService;
    @Override
    public WxQrcodeScanDetailEntity fansLastScanSalesman(String lhotelGroupCode, String memberNo ) throws Exception {
        MemberBase findMember = new MemberBase();
        findMember.setMemberNo(memberNo);
        findMember.setLhotelGroupCode(lhotelGroupCode);
        MemberBase memberBase = commonService.findOneEQ(MemberBase.class, findMember);
        if(memberBase == null){
            return null;
        }
        WxQrcodeScanDetailEntity find = new WxQrcodeScanDetailEntity();
        find.setOpenid(memberBase.getOpenid());
        find.setQrType(WxQrcodeScanConstant.qr_type.SALESMAN);
        HashMap<String,String> sortMap=new HashMap<>();
        sortMap.put(BaseEntity.BaseEntity_.id.toString(),CriteriaUtil.DESC);
        QueryResult<WxQrcodeScanDetailEntity> res = commonDao.findAll(WxQrcodeScanDetailEntity.class, CriteriaUtil.getCriteriaAllEQ(find), 1, 1, sortMap, null);
        if(CollectionUtils.isNotEmpty(res.getResultlist())){
            return res.getResultlist().get(0);
        }else {
            return null;
        }
    }
}
